/**
  ******************************************************************************
  * @file    gt32f030_lvd.h
  * @author  GT Application Team
  * @version V1.0.0
  * @date    03-January-2025
  *       
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 Giantec Semicondutor Inc</center></h2>
  *
  *             http://www.giantec-semi.com/
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __GT32F030_LVD_H
#define __GT32F030_LVD_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "gt32f030.h"

/** @addtogroup GT32F030_StdPeriph_Driver
  * @{
  */

/** @addtogroup LVD
  * @{
  */ 

/* Exported macro ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/

/** @defgroup LVD_Exported_Constants
  * @{
  */
	 
#define  LVD_CR_ENABLE        (uint32_t)0x00000020
#define  LVD_CR_INTENABLE     (uint32_t)0x00008000 
#define  LVD_CR_FLTENABLE     (uint32_t)0x00000080

/** @defgroup LVD_FilterClkSource 
  * @{
  */ 	 
/*
typedef enum
{ 
	LVD_FilterSource_NULL = 0x00,
  LVD_FilterSource_PCLK = 0x01,
  LVD_FilterSource_LIRC = 0x02,
}LVDFilterSource_TypeDef;
#define IS_LVD_FLTSRC(FLTSRC) (((FLTSRC) == LVD_FilterSource_NULL) || \
                               ((FLTSRC) == LVD_FilterSource_PCLK) || \
                               ((FLTSRC) == LVD_FilterSource_LIRC))
*/

typedef enum {
  LVD_FilterSource_PCLK = 0x00,
  LVD_FilterSource_LIRC = 0x01
} LVDFilterSource_TypeDef;

#define IS_LVD_FLTSRC(FLTSRC) (((FLTSRC) == LVD_FilterSource_PCLK) || \
                               ((FLTSRC) == LVD_FilterSource_LIRC))

#define IS_LVD_FLTNUM(FLTNUM)  (((FLTNUM >= 0) &&(FLTNUM <= 0xFFFF)))

/** 
  * @brief  Interrupt Init Structure definition  
  */
typedef struct
{               
  unsigned int LVDFilter_Number;      
  LVDFilterSource_TypeDef LVDFilter_Source;  
  FunctionalState LVDFilter_Cmd;   
}LVDFilter_InitTypeDef;



/**
  * @}
  */ 


/*
#define  LVD_IntTrigger_FALL   0x00001000
#define  LVD_IntTrigger_RISE   0x00002000
#define  LVD_IntTrigger_HIGH   0x00004000
#define IS_LVD_INTTRG(INTTRG) (((INTTRG) == 0) || \
                               ((INTTRG) == LVD_IntTrigger_FALL) || \
                               ((INTTRG) == LVD_IntTrigger_RISE) || \
                               ((INTTRG) == LVD_IntTrigger_HIGH) || \
                               ((INTTRG) == (LVD_IntTrigger_RISE|LVD_IntTrigger_FALL)))
*/

#define LVD_IntTrigger_FALL ((uint32_t)0x04000000)
#define LVD_IntTrigger_RISE ((uint32_t)0x02000000)
#define LVD_IntTrigger_HIGH ((uint32_t)0x01000000)

#define IS_LVD_INTTRG(INTTRG) (((INTTRG) == LVD_IntTrigger_FALL) || \
                               ((INTTRG) == LVD_IntTrigger_RISE) || \
                               ((INTTRG) == LVD_IntTrigger_HIGH))

/** 
  * @brief  Interrupt Init Structure definition  
  */
typedef struct
{               
  unsigned int LVDInt_Trigger;      
  FunctionalState LVDInt_Cmd;    
}LVDInt_InitTypeDef;

typedef enum {
  LVDVoltSel_1_8V = 0x00,
  LVDVoltSel_2_0V = 0x01,
  LVDVoltSel_2_2V = 0x02,
  LVDVoltSel_2_4V = 0x03,
  LVDVoltSel_2_6V = 0x04,
  LVDVoltSel_2_8V = 0x05,
  LVDVoltSel_3_0V = 0x06,
  LVDVoltSel_3_2V = 0x07
} LVDVoltSel_TypeDef;

#define IS_LVD_VOLT(VOLT)  (((VOLT) == LVDVoltSel_1_8V) || \
                           ((VOLT) == LVDVoltSel_2_0V) || \
                           ((VOLT) == LVDVoltSel_2_2V) || \
                           ((VOLT) == LVDVoltSel_2_4V) || \
                           ((VOLT) == LVDVoltSel_2_6V) || \
                           ((VOLT) == LVDVoltSel_2_8V) || \
                           ((VOLT) == LVDVoltSel_3_0V) || \
                           ((VOLT) == LVDVoltSel_3_2V))


/*
#define IS_LVD_VOLT(VOLT)  (((VOLT >= 0) &&(VOLT <= 0x1F)))
*/


/**
  * @}
  */ 

/** @defgroup LVD_CLKOutput_PreScale 
  * @{
  */
/*
typedef enum
{ 
  LVDVSourceSel_Vdd  = 0x00,
  LVDVSourceSel_LVD0 = 0x01,
	LVDVSourceSel_LVD1 = 0x02,
	LVDVSourceSel_LVD2 = 0x03
}LVDVSourceSel_TypeDef;
#define IS_LVD_VSRC(VSRC) (((VSRC) == LVDVSourceSel_Vdd)  || \
                           ((VSRC) == LVDVSourceSel_LVD0) || \
                           ((VSRC) == LVDVSourceSel_LVD1) || \
                           ((VSRC) == LVDVSourceSel_LVD2))
*/

typedef enum {
  LVDVSourceSel_Vdd = 0x00,
  LVDVSourceSel_LVD0 = 0x01 // PB7
} LVDVSourceSel_TypeDef;

#define IS_LVD_VSRC(VSRC) (((VSRC) == LVDVSourceSel_Vdd)  || \
                           ((VSRC) == LVDVSourceSel_LVD0)

/**
  * @}
  */ 

/** @defgroup LVD_ActiveMode 
  * @{
  */
typedef enum
{ 
  LVD_ActiveMode_Interrupt  = 0x00,
	LVD_ActiveMode_Reset      = 0x01
}LVDActiveMode_TypeDef;
#define IS_LVD_ACTMODE(ACTMODE) (((ACTMODE) == LVD_ActiveMode_Reset)     || \
                                 ((ACTMODE) == LVD_ActiveMode_Interrupt))


/**
  * @} end of  LVD_Exported_Constants
  */

/* Exported types ------------------------------------------------------------*/
/** 
  * @brief   LVD Init structure definition  
  */
typedef struct 
{
	LVDVSourceSel_TypeDef   LVD_VSourceSel;
  /*
  unsigned int            LVD_VoltSel; 
  */
  LVDVoltSel_TypeDef LVD_VoltSel;
	LVDActiveMode_TypeDef   LVD_ActiveMode;  
	FunctionalState         LVD_Cmd; 
}LVD_InitTypeDef;


/* Exported functions --------------------------------------------------------*/
void LVD_DeInit(void);
void LVD_Init(LVD_InitTypeDef* LVD_InitStruct);
void LVD_StructInit(LVD_InitTypeDef* LVD_InitStruct);
void LVD_Cmd(FunctionalState NewState);

void LVDInt_DeInit(LVDInt_InitTypeDef* LVDInt_InitStruct);
void LVDInt_Init(LVDInt_InitTypeDef* LVDInt_InitStruct);
void LVDFilter_DeInit(LVDFilter_InitTypeDef* LVDFilter_InitStruct);
void LVDFilter_Init(LVDFilter_InitTypeDef* LVDFilter_InitStruct);

/*
ITStatus LVD_GetIT(void);
*/
void LVD_ClearIT(void);

#ifdef __cplusplus
}
#endif

#endif /* __GT32F030_LVD_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

/************************ (C) COPYRIGHT Giantec Semicondutor Inc *****END OF FILE****/
